#include <iostream>
#include <queue>

using namespace std;

void solve() {
    int n;
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> q1, q0;
    for (int i = 1; i <= n; i++) {
        int t;
        scanf("%1d", &t);
        if (t == 0) {
            q0.push(i);
        } else if (t == 1) {
            q1.push(i);
        }
    }


    int k;
    cin >> k;
    string op;
    cin >> op;
    for (int i = 0; i < op.size(); i++) {

        // cout << op[i] << ' ';
        if (op[i] == 'M') {
            if (q1.empty()) {
                int t = q0.top();
                q0.pop();
                printf("%d\n",t);
                q1.push(t);
            } else {
                int t = q1.top();
                q1.pop();
                printf("%d\n",t);
            }

        } else {
            if (q0.empty()) {
                int t = q1.top();
                q1.pop();
                printf("%d\n",t);
            } else {
                int t = q0.top();
                q0.pop();
                printf("%d\n",t);
                q1.push(t);
            }
        }
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
